<template>
    <view>
        <Header returnIcon="white" :background="background" :title="title" />
        <!--   标题选择组件     -->
        <CheckTitle :titleList="titleList" :checkIndex="checkIndex" @checkChange="checkChange" />
        <view class="content" :style="{'min-height': `${noBarHeight - 58}px`}">
            <!--     项目       -->
            <scroll-view class="pro_main" v-if="checkIndex == 1" scroll-y="true" :style="{'height': `${noBarHeight - 58}px`}" :enhanced="true" :show-scrollbar="false">
                <ProBlack
                    :isStar="true"
                    @onClick="navProject"
                    v-for="(item, index) in dataList"
                    :key="index"
                    :dataDetail="item"
                />
            </scroll-view>
            <!--     企业       -->
            <scroll-view v-if="checkIndex == 2" class="pro_main" scroll-y="true" :style="{'height': `${noBarHeight - 58}px`}" :enhanced="true" :show-scrollbar="false">
                <CompanyBlack
                    isStar="true"
                    @onClick="navCompany"
                    v-for="(item, index) in dataList"
                    :key="index"
                    :dataDetail="item"
                />
            </scroll-view>
            <!--     其他       -->
            <view v-if="checkIndex == 3" class="main">
                <view @click="navInfo(item)" class="content_black" v-for="(item, index) in dataList" :key="index">
                    <view  class="title">标题</view>
                    <img v-if="1 == 1" class="icon" src="https://xunlantech.oss-cn-hangzhou.aliyuncs.com/source/static/image/instar_icon.png" />
                    <img v-else class="icon" src="https://xunlantech.oss-cn-hangzhou.aliyuncs.com/source/static/image/star_icon.png" />
                </view>
            </view>
        </view>
    </view>
</template>
<script>
import CheckTitle from "@/components/CheckTitle.vue";
import Header from "@/components/Header.vue";
import ProBlack from "@/components/ProBlock.vue"
import CompanyBlack from "@/components/CompanyBlock.vue"
import {itemCollect} from "@/utils/api/project";
import {userCollect} from "@/utils/api/company";
import {mMessage} from "@/utils/api/common";
var app = getApp()
export default ({
    name: "collect",
    data() {
        return {
            background: 'linear-gradient(0, #5162FD, #8E4EF7)',
            title: '我的收藏',
            noBarHeight: app.globalData.noBarHeight,
            titleList: [
                {
                    id: 1,
                    title: '项目',
                },
                {
                    id: 2,
                    title: '企业',
                },
                {
                    id: 3,
                    title: '其他',
                }
            ],
            checkIndex: 1,
            pages: {
                total: 0,
                size: 20,
                page: 1,
                isOver: false
            },
            dataList: []
        }
    },
    onLoad() {
        this.getList()
    },
    components: {
        Header,
        CheckTitle,
        ProBlack,
        CompanyBlack
    },
    methods: {
        // 跳转项目详情
        navProject(e) {
            uni.navigateTo({
                url: `../../../detail/pages/projectDetail/projectDetail?id=${e.id}`
            })
        },
        // 跳转企业详情
        navCompany(e) {
            uni.navigateTo({
                url: `../../../detail/pages/companyDetail/companyDetail?id=${e.firm_id}`
            })
        },
        // 重置分页信息
        resetting() {
            this.pages = {
                total: 0,
                size: 20,
                page: 1,
                isOver: false
            }
            this.dataList = []
        },
        async getList() {
            const params = {
                uid: uni.getStorageSync('uid'),
                p: this.pages.page
            }
            let data = {}
            if (this.checkIndex == 1) {
                data = await itemCollect(params)
            } else if (this.checkIndex == 2) {
                data = await userCollect(params)
            } else {
                data = await mMessage(params);
            }
            this.dataList = data.data.data
            this.pages.total = data.data.total
            if (data.data.total < (this.pages.page * this.pages.size)) {
                this.pages.isOver = true
            }
        },
        checkChange(item) {
            this.checkIndex = item
            this.resetting()
            this.getList()
        }
    }
})
</script>

<style scoped lang="scss">
.content {
    flex-direction: column;
    width: 100%;
    background: #f8f8f8;
    display: flex;
    box-sizing: border-box;
    justify-content: space-between;
    align-items: center;
    .icon {
        width: 40rpx;
        height: 40rpx;
    }
    .pro_main {
        width: 100%;
        padding: 12rpx 12rpx 0;
        box-sizing: border-box;
    }
    .main {
        padding-top: 12rpx;
        box-sizing: border-box;
        width: 100%;
        .content_black {
            background: white;
            width: 100%;
            height: 88rpx;
            display: flex;
            align-items: center;
            justify-content: space-between;
            padding: 20rpx 30rpx 20rpx 20rpx;
            box-sizing: border-box;
            border-bottom: 2rpx solid #efefef;
            .title {
                height: 40rpx;
                font-size: 28rpx;
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                color: #494949;
                line-height: 40rpx;
                width: 57%;
            }
            .time {
                width: 40%;
                height: 33rpx;
                font-size: 24rpx;
                font-family: PingFangSC, PingFang SC;
                font-weight: 400;
                color: #9B9B9B;
                line-height: 33rpx;
                text-align: right;
            }
        }
    }
}
</style>
